package com.qcby.controller;

import com.qcby.dao.TeacherDao;
import com.qcby.entity.*;
import com.qcby.service.Iface.StudentService;
import com.qcby.service.Iface.TeacherService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/teacher")
public class teacherController {
    @Resource
    private TeacherService teacherService;
    @RequestMapping("/indexHomePage.do")
    public String returnHomePage(){
        return "indexTeacher";
    }
    @RequestMapping("/findAllTeacher.do")
    @ResponseBody
    public List<Teacher> findAll(){
        return teacherService.findAll();
    }

    @RequestMapping("/findAllCount.do")
    @ResponseBody
    public int findAllCount(){
        System.out.println(teacherService.findAllCount());
        return teacherService.findAllCount();
    }
    @RequestMapping("/findAllCountBySearch.do")
    @ResponseBody
    public int findAllCountBySearch(HttpServletRequest request){
        String name= "%"+request.getParameter("name")+"%";
        String sex=  "%"+request.getParameter("sex")+"%";
        Teacher teacher=new Teacher();
        teacher.setSex(sex);
        teacher.setName(name);
        return teacherService.findAllCountBySearch(teacher);
    }
    @RequestMapping("/findAllBySearch.do")
    @ResponseBody
    public List<Teacher> findAllBySearch(HttpServletRequest request){
        String name= "%"+request.getParameter("name")+"%";
        String sex=  "%"+request.getParameter("sex")+"%";
        Teacher teacher=new Teacher();
        teacher.setSex(sex);
        teacher.setName(name);
        teacher.setStartPage(request.getParameter("startPage"));
        teacher.setEndPage(request.getParameter("endPage"));
        System.out.println(teacher);
        return teacherService.findAllBySearch(teacher);
    }
    @RequestMapping("/addPage.do")
    public String hrefAddPage(){
        return "addTeacher";
    }
    @RequestMapping("/updatePage.do")
    public String returnUpdatePage(){
        return "updateTeacher";
    }
    @RequestMapping("/lookOther.do")
    public String lookOther(){
        return "detailTeacher";
    }
    @RequestMapping("backHomePage.do")
    public String backToHomePage(){
        return "indexTeacher";
    }
    @RequestMapping("/addTeacher.do")
    @ResponseBody
    public int addStudent(Teacher teacher){
        return teacherService.addTeacher(teacher);
    }
    @RequestMapping("/updateTeacherInfro.do")
    @ResponseBody
    public Teacher updateStudentInfro(HttpServletRequest httpServletRequest){
        int id= Integer.parseInt(httpServletRequest.getParameter("id"));
        return  teacherService.updateTeacherInfro(id);
    }
    @RequestMapping("/update.do")
    @ResponseBody
    public int  updateStudent(Teacher teacher){
        return teacherService.updateTeacher(teacher);
    }
    @RequestMapping("/loadTeacherClass.do")
    @ResponseBody
    public List<Clazz> loadTeacherClass(HttpServletRequest request){
        int id= Integer.parseInt(request.getParameter("id"));
        return teacherService.loadTeacherClass(id);
    }
    @RequestMapping("/detailCourse.do")
    public String detailCourse(){
        return "detailTeacherCourse";
    }
    @RequestMapping("/findOneTeacherCourse.do")
    @ResponseBody
    public List<Course> findOneTeacherCourse(HttpServletRequest request){
        int id= Integer.parseInt(request.getParameter("id"));
        return teacherService.loadTeacherCourse(id);
    }
    @RequestMapping("/returnTeacherDetail.do")
    public String returnTeacherDetail(){
        return "detailTeacher";
    }
    @RequestMapping("/detailClass.do")
    public String detailClass(){
        return "detailTeacherClass";
    }
    @RequestMapping("/findOneTeacherClass.do")
    @ResponseBody
    public List<Student> findOneTeacherClass(HttpServletRequest request){
        int id= Integer.parseInt(request.getParameter("id"));
        return teacherService.findOneTeacherClass(id);
    }
    @RequestMapping("delete.do")
    @ResponseBody
    public Tell delete(HttpServletRequest request){
        int id= Integer.parseInt(request.getParameter("id"));
        Tell tell =new Tell();
        tell.setMsg(teacherService.delete(id));
        return tell;
    }
}
